/**
 * 添加快捷菜单向导
 */
Ext.namespace("Ext.ux.config");

Ext.ux.config.InitConfigWizard = Ext.extend(Ext.ux.Wiz, {

	title: '配置向导',
	width: 600,
	
	password: null,		//用户密码
	isImportOrg: null,	//是否导入机构
	isImportRigth: null,	//是否导入权限

	cardPanelConfig: { 
		defaults: {
			bodyStyle: 'padding:40px 30px 5px 30px;background-color:#F6F6F6;', 
			border: false     
		}
	},

	initComponent: function(){
	
		//配置向导每个cards的提示信息
		var wizardInfoOfCards = new Array();
		wizardInfoOfCards[0] = "<span style='font-family:verdana;font-size:120%'>第一步：设置系统管理员密码</span><br><br><span style='font-size:100%;color: gray'>&nbsp;系统管理员默认登录帐号为aosadmin，请输入大于3位且小于等于30位的密码。</span>";
		wizardInfoOfCards[1] = "<span style='font-family:verdana;font-size:120%'>第二步：导入示例数据</span><br><br><span style='font-size:100%;color: gray'>&nbsp;选择是否导入示例的机构数据和权限（包括角色、应用功能、菜单）数据。</span>";
		wizardInfoOfCards[2] = "<span style='font-family:verdana;font-size:120%'>第三步：完成初始化配置</span><br><br><span style='font-size:100%;color: gray'>&nbsp;请仔细阅读以下初始化配置信息，点击“上一步”可更改配置，点击“完成”则执行初始化操作。</span>";
		this.wizardInfoOfCards = wizardInfoOfCards;
	
		this.initCards();
		this.closable=false;	//不允许关闭窗口
		
		Ext.ux.config.InitConfigWizard.superclass.initComponent.call(this);
	},
	
	//单击上一步
	onPreviousClick: function(){
		if(this.currentCard == 1){
			document.getElementById('passNotMatch').innerHTML = "";
		}
		Ext.ux.config.InitConfigWizard.superclass.onPreviousClick.call(this);
	},
	
	//单击下一步
	onNextClick: function(){
		 if(this.currentCard == 0){
		 	if(!this.cards[0].isPasswordMatch()){
		 		this.cardPanel.getLayout().setActiveItem(0);
		 		this.cards[0].showPasswordIsNotMatch();
		 		return;
		 	}
		 	if(!this.cards[0].form.isValid()){
		 		this.cardPanel.getLayout().setActiveItem(0);
		 		return;
		 	}
		 	//设置密码
		 	this.password = this.cards[0].form.findField('pwd').getValue();
		 }
         Ext.ux.config.InitConfigWizard.superclass.onNextClick.call(this);
	},
	onFinish: function(){
		//Ext.ux.config.InitConfigWizard.superclass.onFinish.call(this);
		Ext.Ajax.request({
			url: 'init-config!init.action',
			success: function(){
				Ext.Msg.alert('系统提示','后台系统管理已成功初始化，请刷新当前页或直接访问系统首页！');
			},
			failure: function(){
				Ext.Msg.alert('系统提示','初始化配置操作失败！');
			},
			params: {
				aosAdminPassword: this.getPassword(),
				importOrgData: this.getIsImportOrg() ? '1' : '0',
				importRightData: this.getIsImportRight() ? '1' : '0'
			},
			scope: this
		});
	},
	
	initCards: function(){
	
		var card1 = new Ext.ux.config.AosAdminPasswordPanel({wizardWin:this});
		var card2 = new Ext.ux.config.ImportDemoDataPanel({wizardWin:this});
		var card3 = new Ext.ux.config.ShowCofigInfoPanel({wizardWin:this});
		
		var cards = new Array();
		cards[0] = card1;
		cards[1] = card2;
		cards[2] = card3;
		this.cards = cards;
	},
	
	getPassword: function(){
		return this.password;
	},
	
	getIsImportOrg: function(){
		return this.cards[1].getIsImportOrg();
	},
	
	getIsImportRight: function(){
		return this.cards[1].getIsImportRight();
	}
});